package com.sunfeng.n4.singleton;

/**
 * DCL   这种写法如同  SingletonTwo
 */
public class DoubleChecked {

    private DoubleChecked() {

    }

    public static volatile DoubleChecked doubleChecked = null;

    public static DoubleChecked getInstance() {
        if (doubleChecked == null) {
            //synchronized 不能阻止重排序
            synchronized (DoubleChecked.class) {
                if (doubleChecked == null) {
                    // 发生指令重排
                    doubleChecked = new DoubleChecked();
                }
            }
        }
        return doubleChecked;
    }


}
